<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>中止施工</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <!--<script type="text/javascript" src="/templates/act/process-xl.js"></script>-->
    <style>
        .content {
            position: relative;
        }

        .btnBox {
            position: absolute;
            top: 10px;
            right: 10px;
            z-index: 1000;
        }
    </style>
</head>
<body>
<div class="content" id="view">

</div>
<script src="/static/js/main.js"></script>
<script type="text/javascript">
    layui.use(['configureCom', 'configure', 'bluebird', 'baseTab', 'sessionFun', 'jquery', 'process'], function () {
        var configure = layui.configure;
        var configureCom = layui.configureCom;
        var baseTab = layui.baseTab;
        var sessionFun = layui.sessionFun;
        var process = layui.process;
        var $ = layui.jquery;

        // 流程待办信息
        var procWaitDealRowData = sessionFun.get(configure.SESSION_PROC_WAIT_DEAL_ROW_DATA);

        // 申请记录查看详情或修改
        var pauseRowData = sessionFun.get(configure.PAUSE_ROW_DATA);

        // 项目信息
        var rowData = sessionFun.get(configure.SESSION_PROJECT_LIST_DATA);

        var baseData = sessionFun.get('baseData');


        var pauseId = sessionFun.get('pauseId');
        console.log("pauseId:::::::::::::::::::::"+pauseId);

        // 中止施工-申请
        var pause_sq = {
            tabData :{
                btns: [
                    {name: '保存', event: 'save'},
                    {name: '提交申请', event: 'submit'},
                    {name: '关闭', event: 'close'}
                ],
                tabList: [
//                    { title: '项目信息', url: configure.UNIT_PROJECT_PROHIBITED_DETAIL_HTML},
                    { title: '中止施工-申请', url:'/pages/pause/detail.html'}
                ]
            },

            save: function(){
                configureCom.getData(0).then(function (res) {
                    configureCom.postDataAjax(configure.PAUSE_SAVE_API, res.result).then(function (res) {
                        top.layer.msg('保存成功！');
                    })
                });
            },

            submit: function() {
                configureCom.getData(0).then(function (res) {
                    configureCom.postDataAjax(configure.PAUSE_SAVE_API, res.result).then(function (res) {
                        var prjPause = res.prjPause;
                        console.log(prjPause);
                        process.startProcess({
                            "title": "中止施工 - " + prjPause.prjName,
                            "businessId": prjPause.id,
                            "procDefKey": 'ZZSG'
                        });
                    })
                });
            },

            init: function(){
                //如果是申请记录页面进来, 并且状态不是0 不允许修改
                if(pauseRowData && pauseRowData.status!=0){
                    this.tabData.btns = [
                        {name: '关闭', event: 'close'}
                    ];
                }
                baseTab.init(this.tabData, 0);
                form.on('submit', function (data) {
                    var event = $(data.elem).attr('lay-event');
                    switch (event) {
                        case 'save':
                            pause_sq.save();
                            break;
                        case 'submit':
                            pause_sq.submit();
                            break;
                    }
                    return false;
                });
            }
        };

        // 中止施工-审批
        var pause_sp = {
            tabData :{
                btns: [
                    {name: '保存', event: 'save'},
                    {name: '保存并提交', event: 'submit'},
                    {name: '关闭', event: 'close'}
                ],
                tabList: [
                    { title: '中止施工-申请', url:'/pages/pause/detail.html'},
                    { title: '中止施工-审批', url:'/pages/pause/sp.html'}
                ]
            },

            save: function(){
                configureCom.getData(1).then(function (res) {
                    configureCom.postDataAjax(configure.PAUSE_SP_API, res.result).then(function (res) {
                        top.layer.msg('保存成功！');
                    })
                });
            },

            submit: function() {
                configureCom.getData(1).then(function (res) {
                    configureCom.postDataAjax(configure.PAUSE_SP_API, res.result).then(function (res) {
                        var prjPause = res.prjPause;
                        console.log(prjPause);
                        process.next({
                            "taskId": procWaitDealRowData.id,
                            "poId": procWaitDealRowData.poId
                        });
                    })
                });
            },

            init: function(){
                baseTab.init(this.tabData, 1);
                form.on('submit', function (data) {
                    var event = $(data.elem).attr('lay-event');
                    switch (event) {
                        case 'save':
                            pause_sp.save();
                            break;
                        case 'submit':
                            pause_sp.submit();
                            break;
                    }
                    return false;
                });
            }
        };



        console.log(procWaitDealRowData)
        if(procWaitDealRowData!=null){
            var taskDefKey =  procWaitDealRowData.taskDefKey;
            if(taskDefKey === 'jszzsgsq' ){
                pause_sq.init();
            }else if(taskDefKey === 'jgzzsgsp'){
                pause_sp.init();
            }else{
                pause_sq.init();
            }
        }else{
            pause_sq.init();
        }



    });


</script>
</body>
</html>